<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/order/css/address.css"/>
    <script type="text/javascript" src="__TMPL__/public/order/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
    <title>收货地址</title>
</head>
<body>
<header>
    <div class="content"  style="border-bottom: 1px solid rgba(215, 215, 215, 0.29);">
        <php> if(input('type')==null){ </php>
        <a href="/user/profile/center.html" ></a>
        <php> }else{</php>
        <a href="/shop/order/index.html" ></a>
        <php>}</php>
        <a>收货地址</a>
        <a href="javascript:;"></a>
    </div>
</header>

<div class="aadress" <empty name="address_list">style="display: none"</empty>>
    <foreach name="address_list" item="vo">
        <php>
            if(input('type')){
                $href="onclick='location.href=\"/user/profile/edit_order_address/id/".$vo['id'].".html\"'";
            }else{
                $href="";
            }
        </php>
        <div class="ads1"  >
            <div class="ad_list">
                <div class="radio" style="display: none;"></div>
                <div {$href}>
                    <p class="name"><span>{$vo['consigner']}</span><span>{$vo['mobile']}</span></p>
                    <p class="detail"><span style="height: 30px;overflow: hidden;display: block;">{:get_city_info($vo['province'],$vo['city'],$vo['district'])}{$vo['address']}</span></p>
                    <p class="default" data="{$vo['id']}">
                        <eq name="vo['is_default']" value="0">
                            <span class="w_select">
                                  <img src="__TMPL__/public/order/img/icon_radio3.png" class="fal"/>  <span>设为默认</span>
                            </span>
                            <span class="select">
                                <img src="__TMPL__/public/order/img/icon_radio4.png" class="tru"/> <span>设为默认</span>
                            </span>
                        </eq>
                        <eq name="vo['is_default']" value="1">
                            <span class="w_select" style="display: none;">
                                  <img src="__TMPL__/public/order/img/icon_radio3.png" class="fal"/>  <span>设为默认</span>
                            </span>
                            <span class="select" style="display: inline;">
                                <img src="__TMPL__/public/order/img/icon_radio4.png" class="tru"/> <span>设为默认</span>
                            </span>
                        </eq>
                    </p>
                </div>
                <div><img src="__TMPL__/public/order/img/change.png" onclick="location.href='{:url(\'user/profile/edit_address\',array(\'id\'=>$vo[\'id\'],\'type\'=>input(\'type\')))}'"/></div>
             </div>
             <i data="{$vo['id']}" class="del">删除</i>
        </div>

    </foreach>


</div>
<div  <empty name="address_list">style="margin-top: 50%;"</empty><notempty name="address_list">style="display: none;margin-top: 50%;"</notempty>>
    <img src="__TMPL__/public/order/img/member_none_address.png" style="margin: 0 auto; display: block; margin-top: 10px;">
    <div class="addr-box">
        <p class="addr-tip">你还没有添加收货地址，添加一个吧!</p>
    </div>
</div>

<div class="add"><a href="{:url('user/profile/add_address',array('type'=>input('type')))}" style="color: #d9b97c;">新建收货地址</a></div>
</body>
<script type="text/javascript">
    $(".default").click(function(){
       $('.w_select').show();
       $('.select').hide();
       $(this).children('.select').show();
       $(this).children('.w_select').hide();
       var data=$(this).attr('data');
        $.ajax({
            url : '/user/profile/default_address.html',
            type : "post",
            data : {
                "id" : data
            },
            success : function(res){
                layer.msg(res.msg);
            }
        });
    });
    $(".del").click(function(){
        var o=$(this);
        var data=$(this).attr('data');
        $.ajax({
            url : '/user/profile/del_address.html',
            type : "post",
            data : {
                "id" : data
            },
            success : function(res){
                layer.msg(res.msg);
                o.parent('.ads1').remove();
            }
        });
    });
</script>
<script>
    //侧滑显示删除按钮
    var expansion = null; //是否存在展开的list
    var container = document.querySelectorAll('.ad_list');
    for(var i = 0; i < container.length; i++){
        var x, y, X, Y, swipeX, swipeY;
        container[i].addEventListener('touchstart', function(event) {
            x = event.changedTouches[0].pageX;
            y = event.changedTouches[0].pageY;
            swipeX = true;
            swipeY = true ;
            if(expansion){   //判断是否展开，如果展开则收起
                expansion.className = "ad_list";
            }
        });
        container[i].addEventListener('touchmove', function(event){

            X = event.changedTouches[0].pageX;
            Y = event.changedTouches[0].pageY;
            // 左右滑动
            if(swipeX && Math.abs(X - x) - Math.abs(Y - y) > 0){
                // 阻止事件冒泡
                event.stopPropagation();
                if(X - x > 10){   //右滑
                    event.preventDefault();
                    this.className = "ad_list";    //右滑收起
                }
                if(x - X > 10){   //左滑
                    event.preventDefault();
                    this.className = "ad_list swipeleft";   //左滑展开
                    expansion = this;
                }
                swipeY = false;
            }
            // 上下滑动
            if(swipeY && Math.abs(X - x) - Math.abs(Y - y) < 0) {
                swipeX = false;
            }
        });
    }
</script>
</html>
